<template>
		<view>
			<web-view :src="src"></web-view>
			</view>
<!-- 			<view>
			    <button class="cu-btn bg-olive"  @click="resumeAnimation()">继续动画</button>
			    <button class="cu-btn bg-red"  @click="stopAnimation()">停止动画</button>
			    <button class="cu-btn bg-olive"  @click="startAnimation()">开始动画</button>
			    <button class="cu-btn bg-red"  @click="pauseAnimation()">暂停动画</button>
			</view> -->
		</view>

</template>
<script>
	export default {

		onLoad(option){
			// const specSelected = JSON.parse(decodeURIComponent(option.specSelected));
			// this.specSelected = specSelected;
			// console.log(decodeURIComponent(option.specSelected));
			this.src='../../../hybrid/html/orderMap.html?data=';
			this.src+=decodeURIComponent(option.specSelected);
		
		},
		data() {
			return {
				src:'',
				timer:null,//定时刷新任务
				Loop:null,   //这是一个按钮时长定时器
				callTF:false,
				nums:'请求车辆',
				start: '104.068818,30.60138',
				end: '103.969563,30.31744',
				price: '',
				userId:5,
				specSelected: {
					startAddress:'成都蜗牛学院天府校区',
					endAddress:'成都天府广场',
					rectangle: '',
					distance: null, //距离
					trucksId:'',
				}
			};
		},
	mounted() {
		
			},
	methods: {
		CallCarsMap2() {
				console.log('点击了请求');
					if(this.callTF==false){
					var ss=this;
				// console.log('触发了请求车辆',ss.specSelected.trucksId);
					uni.showModal({
						title: '订单信息',
						content: '您的订单预估金额为' + ss.price+'是否要下单',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定',ss.specSelected);
								ss.doOrder();
								ss.callTF=true;
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					}
				},
				//在方法中将以下方法复制过去即可应用。
				showDeleteButton() {
				    clearTimeout(this.Loop); //再次清空定时器，防止重复注册定时器
					var ss=this;
				    this.Loop = setTimeout(function() {
					this.underOrder();
				    }.bind(this),1000);
				},
				//清空
				emptyTime() {
				    clearTimeout(this.Loop); //清空定时器，防止重复注册定时器
				},
				Howmoeny(specSelected) {
					uni.request({
						url: 'https://restapi.amap.com/v3/direction/walking?origin='+this.start+'&destination='+this.end+'&key=1f5cfb770d01a1a0d8289169188de6b3',
						// data:{
						// 	origin: this.start,
						// 	destination: this.end,
						// 	key:'1f5cfb770d01a1a0d8289169188de6b3',
						// },
						success: res => {
							if (res.data.status) {
								// console.log('计算价格的请求进来了');
								this.specSelected.distance =res.data.route.paths[0].distance;
								// console.log('路程距离为'+this.specSelected.distance);
								uni.request({
									url: this.baseurl +'order/Howmoney',
									method: 'POST',
									dataType: 'json',
									data: {
										uid: specSelected.userId,
										price: specSelected.price,
										tid: specSelected.trucksId,
										distance: this.specSelected.distance,
									},
									success: res => {
										if (res.data.flag) {
											this.price = res.data.data;
										console.log(res);
										}
									}
								});
							}
						}
					});
				},
				doOrder(){
					console.log('向后端传值'+this.specSelected);
					uni.request({
						url: this.baseurl+'order/doOrder',
						method: 'POST',
						dataType: 'json',
						data: {
							order: {
								uid:this.userId,
								tid:this.specSelected.trucksId,
								cid:this.specSelected.comId,
								totalAmount:this.price,
								distance: this.specSelected.distance,
							},
							address: {
								startAddress: this.specSelected.startAddress,
								endAddress: this.specSelected.endAddress,
								uidxy: this.specSelected.rectangle,
							}
						},
						success: res => {
							if (res.data.flag) {
								this.timeSave();
							}
						}
				})
			},
			//计时器
			timeSave() {
						var my_self = this;
						this.nums=null;
						var hour, minute, second; /*时 分 秒*/
						hour = minute = second = 0; //初始化
						var millisecond = 0; //毫秒
						this.timer = setInterval(() => {
							millisecond = millisecond + 50;
							// console.log("---millisecond----"+millisecond);
							if (millisecond >= 1000) {
								millisecond = 0;
								second = second + 1;
							}
							if (second >= 60) {
								second = 0;
								minute = minute + 1;
							}
			 
							if (minute >= 60) {
								minute = 0;
								hour = hour + 1;
							}
							// console.log("-------"+hour+'时'+minute+'分'+second+'秒');
							this.nums = hour+'时'+minute+'分'+second+'秒';
						}, 50);
				},
			endtime() {
				 clearInterval(this.timer);
			},
			//取消订单的方法
			underOrder(){
				var ss=this;
				uni.showModal({
					title: '取消订单',
					content: '确定要取消订单吗',
					success: function(res) {
						if (res.confirm) {
						console.log('确定取消订单'+ss.callTF);
							ss.callTF=false;
							ss.endtime();//停止
							ss.nums='请求车辆';
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
				},
				//司机的方法
				DriverGo(){
					console.log('司机订单列表前往')
					uni.navigateTo({
						url:'/pages/movehouse/dirver/dirver',
					});
				}
			},
		};
</script>

<style>
	.amap-demo {
		height: 90vh;
		width: 100%;
	}

	.search-box {
		position: absolute;
		top: 75px;
		left: 45px;
	}

	.amap-page-container {
		position: relative;
	}
	    .loadingTip {
	        position: absolute;
	        z-index: 10;
	        top: 0;
	        left: 0;
	        padding: 3px 10px;
	        background: red;
	        color: #fff;
	        font-size: 14px;
	    }
		.car-jd{
			top:10px;
			left: 160px;
			right: 0;
		}
</style>
